#pragma once

#include <iostream>
#include <chrono>
#include <string>
#include <ctime>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <deque>
#include <string>
#include <vector>
#include <mutex>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <memory>
#include <variant>
#include <random>
#include <chrono>
#include <ctime>
#include <optional>
#include <condition_variable>
#include <utility>
#include <cstddef>
#include <thread>
#include <iomanip>

static std::string nowstr() {
    auto now = std::chrono::system_clock::now();
    std::time_t tt = std::chrono::system_clock::to_time_t(now);
    std::tm* local_time = std::localtime(&tt);
    auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
        now.time_since_epoch()) % 1000;
    char buffer[80];
    std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", local_time);
    std::stringstream s;
    s << " [" << buffer << "."
              << std::setw(3) << std::setfill('0') << ms.count()
              << "]";
    std::string nowstr = s.str();
    return nowstr;
}

#ifdef DEBUG
#define LOG(msg) std::cout << "[DEBUG] " << nowstr() << __FILE__ << ":" << __LINE__ << " " << msg << std::endl
#define LOGE(msg) std::cerr << "[DEBUG] " << nowstr() << __FILE__ << ":" << __LINE__ << " " << msg << std::endl
#else
#define LOG(msg) do {} while (0)
#define LOGE(msg) do {} while (0)
#endif